Java Blog

Since I'm very lazy in sharing my thoughts, this blog may contain very few posts - so please be patient! :-)

Freitag, Juli 23, 2004

OutOfMemoryError Warning System

One of my first experiences of the new JDK 1.5 came as a description of an OutOfMemoryError Warning System in the following newsletter:

2004-07-20 The Java Specialists' Newsletter [Issue 092].

Whom of us has never stepped into this pitfall of the Java VM when it comes to low memory? The most accepted and widely used counter measure is to increase the heap size in the JVM options - just change the -Xmx value and restart the JVM.

But you always have to find the right value. Otherwise you are trapped between low application performance because of a max heap value too high (the garbage collector just needs to much cpu time too clean up dead objects) and the diabolish OutOfMemoryError.

In the newsletter above Dr. Kabutz describes a nifty (a new word of my vocabulary :o)) alternative: dynamic increasing of the heap size. Even if it's implemented with JDK 1.5 means, it shows how much more elaborated the JVM has become. To me it seems the guys at Sun are trying hard to improve the JVMs flaws in regard to performance and - especially here - memory management and consumption.

The one thing I did not like with that solution is the "magical" downcast from the interface java.lang.MemoryMXBean to the completely unrelated interface java.lang.NotificationEmitter. This leaves me with a bad gut feeling, although it's described in the official Sun javadoc of the MemoryMXBean.


MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
NotificationEmitter emitter = (NotificationEmitter) mbean;


Although I'm not using the new JDK yet, I'm looking forward to it and for sure will come back to this tip when I need it!

Cheers,

René

Labels: ,